#include "World.h"

void World::setStart(Coord pStart) {
	start = pStart;
}

void World::setEnd(Coord pEnd) {
	end = pEnd;
}

void World::addLand(int pId, Land *pLand) {
	lands.insert(std::pair<int, Land*>(pId, pLand));
}

void World::addTile(Coord pCoord, Tile *pTile) {
	board.insert(std::pair<Coord, Tile*>(pCoord, pTile));
}

void World::addObject(int pId, TileObject *pObject) {
	objects.insert(std::pair<int, TileObject*>(pId, pObject));
}

bool World::doesLandExist(int pId) {
	return (lands.find(pId) != lands.end());
}

bool World::doesObjectExist(int pId) {
	return (objects.find(pId) != objects.end());
}

Land * World::findLand(int pId) {
	std::map<int, Land*>::iterator it = lands.find(pId);
	if (it == lands.end()) {
		return NULL;
	}
	return (it->second);
}

TileObject * World::findObject(int pId) {
	std::map<int, TileObject*>::iterator it = objects.find(pId);
	if (it == objects.end()) {
		return NULL;
	}
	return (it->second);
}

std::map<int, Land*> & World::getLands() {
	return lands;
}

std::map<int, TileObject*> World::getObjects() {
	return objects;
}

std::map<Coord, Tile*> World::getBoard() {
	return board;
}

int World::getTileCount() {
	return (end.getX() - start.getX() + 1) * (end.getY() - start.getY() + 1);
}

bool World::isCoordOnBoard(Coord pCoord) {
	int x = pCoord.getX();
	int y = pCoord.getY();
	return x >= start.getX() && x <= end.getX() && y >= start.getY() && y <= end.getY();
}
